<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }
    body{
        text-align: center;
    }
    img {
        width: 100px;
        height: 100px;
    }
</style>

<body>
    <div>
        <img src="./img/1.jpg" alt="" ondblclick="fun(this)">
        <img src="./img/2.jpg" alt="" ondblclick="fun(this)">
        <img src="./img/3.jpg" alt="" ondblclick="fun(this)">
        <img src="./img/4.jpg" alt="" ondblclick="fun(this)">
        <img src="./img/5.jpg" alt="" ondblclick="fun(this)">
        <img src="./img/6.jpg" alt="" ondblclick="fun(this)">
        <img src="./img/7.jpg" alt="" ondblclick="fun(this)">
    </div>

</body>
<script>

    function fun(obj) {
        // var src = obj.src
        document.body.style.background = `url(${obj.src}) no-repeat`
        document.body.style.backgroundSize = '100%'
        localStorage.setItem('src', obj.src)
    }
    window.onload = function () {
        document.body.style.background = `url(${localStorage.getItem('src')}) no-repeat`
        document.body.style.backgroundSize = '100%'
        // localStorage.setItem('src', obj.src)
    }


    // function fun(num) {
    //     localStorage.setItem('src', num)
    //     // console.log(localStorage.getItem('img'));
    //     if (num == 1) {
    //         document.body.style = 'background:url(./img/1.jpg) no-repeat;background-size: 100%;'
    //     } else if (num == 2) {
    //         document.body.style = 'background:url(./img/2.jpg) no-repeat;background-size: 100%;'
    //     } else if (num == 3) {
    //         document.body.style = 'background:url(./img/3.jpg) no-repeat;background-size: 100%;'
    //     } else if (num == 4) {
    //         document.body.style = 'background:url(./img/4.jpg) no-repeat;background-size: 100%;'
    //     } else if (num == 5) {
    //         document.body.style = 'background:url(./img/5.jpg) no-repeat;background-size: 100%;'
    //     } else if (num == 6) {
    //         document.body.style = 'background:url(./img/6.jpg) no-repeat;background-size: 100%;'
    //     } else if (num == 7) {
    //         document.body.style = 'background:url(./img/7.jpg) no-repeat;background-size: 100%;'
    //     }
    //     localStorage.setItem('num',num)

    // }
    // window.onload = function () {
    //     localStorage.getItem('num')
    //     // fun(sum)
    // }

</script>

</html>